package org.qpcr.community.project.web;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.qpcr.community.project.model.entity.DataGroupTypeEntity;
import org.qpcr.community.project.request.DataAnalysisRequest;
import org.qpcr.community.project.response.DataAnalysisResultResponse;
import org.qpcr.community.project.response.DataGroupTypeDetail;
import org.qpcr.community.project.service.DataGroupTypeService;

import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping({"/project/data-group-type", "/project/data/group-type"})
@Authorize(ignore = true)
@Resource(id = "data-group-type", name = "数据组别记录")
@Slf4j
@Tag(name = "数据组别记录接口")
@RequiredArgsConstructor
public class DataGroupTypeController implements
    ReactiveServiceCrudController<DataGroupTypeEntity, String> {

    @Getter
    private final DataGroupTypeService service;


    @GetMapping("list/{groupId}")
    @Authorize(ignore = true)
    public Mono<List<DataGroupTypeDetail>> listByGroupId(@PathVariable String groupId) {
        return service.listByGroupId(groupId);
    }

    @GetMapping("{id}/detail")
    @Authorize(ignore = true)
    public Mono<DataGroupTypeDetail> detail(@PathVariable String id) {
        return service.detail(id);
    }

    @PostMapping("analysis")
    @Authorize(ignore = true)
    public Mono<DataAnalysisResultResponse> analysis(@RequestBody DataAnalysisRequest  dataAnalysisRequest) {
        return service.analysis(dataAnalysisRequest);
    }

    @PostMapping("export")
    @Authorize(ignore = true)
    public Mono<Void> export(@RequestBody DataAnalysisRequest dataAnalysisRequest, ServerHttpResponse response) {
        return service.export(dataAnalysisRequest, response);
    }

    @PostMapping("test-export")
    @Authorize(ignore = true)
    public Mono<String> testExport(@RequestBody DataAnalysisRequest dataAnalysisRequest) {
        return service.testExport(dataAnalysisRequest);
    }
}
